home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / iwf12.zip / IWF.C < prev    next >
C/C++ Source or Header  |  1994-02-20  |  29KB  |  891 lines

  1. /*
  2. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. IWF.C (Image WorkFrame)
  4.  
  5. AUTHOR: Craig Muller P. Eng. 1991,1992,1993
  6.         cmuller@ccu.umanitoba.ca
  7.         Computer Vision Laboratory
  8.         Mech. Engn.,Univ. of Manitoba
  9.         Winnipeg, Manitoba. R3T 2N2
  10.  
  11. DESCRIPTION:
  12. This is the main program file for the Image WorkFrame
  13. System or IWF for short. The purpose of this software is to provide a
  14. general purpose program interface for image processing and image manipulation
  15. in a windows environment. The code can be cut an pasted to produce other
  16. programs of used as is. The program also allows the user to control the
  17. MVP-AT image capture board to perform capture and store of images.
  18.  
  19. All the code is designed in a modular fashion so that projects in image
  20. processing or conputer vision do not need to re-write all the basic code
  21. for image manipulation. Each additional software project is designed as an
  22. addition to the and has its own header file which is included here.
  23. Programmers should limit their code modifications to the program module
  24. which contains their project.
  25.  
  26. Coding conventions:
  27.  
  28.    ~~~ boxing for module title and description.
  29.    --- boxing for procedures which can be called by the user.
  30.    === boxing for exports which cannot be called by the user.
  31.  
  32. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. */
  34. #include <windows.h>
  35.  
  36. #pragma hdrstop
  37.  
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include <io.h>
  41. #include <math.h>
  42.  
  43. #include "iwf.h"
  44. #include "module.h"
  45.  
  46. #define  PGMNAME "IWF"
  47. #define  MODULE  "IWF"
  48.  
  49. #define   VGA      640                 // VGA resolution width
  50. #define  SVGA      800                 // Super VGA resolution width
  51. #define   XGA     1024                 // XGA resolution width
  52. #define   CAD     1280                 // CAD/CAM resolution width
  53.  
  54. //========================================
  55. // Exported procedure prototypes.
  56. //========================================
  57. long far PASCAL _export WP_Main (HWND hWnd,WORD wMsg,WORD wParam,LONG lParam);
  58. BOOL FAR PASCAL _export DP_About(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  59. BOOL FAR PASCAL _export DP_Info(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  60. BOOL FAR PASCAL _export DP_Scale(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  61. BOOL FAR PASCAL _export DP_Transform(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  62. BOOL FAR PASCAL _export DP_Frame(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  63. BOOL FAR PASCAL _export DP_UserFile(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  64.  
  65.  
  66. //---------------------------------------
  67. // Private procedures.
  68. //---------------------------------------
  69. static void Load_Settings(void);
  70.  
  71. int UserDlgMessage(MSG *msg);
  72. int ToolDlgMessage(MSG *msg);
  73.  
  74. void Labeller(void);
  75. void FillColors(void);
  76. void iwf_FrameOp(int action);
  77. int Load_Item(FILE *fp,char *keyword,int *buf,int cItems);
  78.  
  79. IMAGE *MedianImage(IMAGE *image);
  80. IMAGE *SobelImage(IMAGE *image,WORD Threshold,BOOL Overlay);
  81.  
  82. //---------------------------------------
  83. // Public variables.
  84. //---------------------------------------
  85.  
  86. HANDLE    hInst;                          /* current instance handle   */
  87.  
  88. HWND  _hWndImage [MAXIMAGES];          // Window handles for images.
  89. HWND  _hWndModule[MAXMODULES];         // Window handles for modules
  90. HWND  _hWndTool  [MAXTOOLS];           // Window handles for buttons
  91. HWND  hWndMod=NULL;                    // Window handle for module.
  92. HWND  hWndSrc=NULL;                    // Window handle for source image.
  93. HWND  hWndDst=NULL;                    // Window handle for destination image.
  94.  
  95. char  _name[8][20];                    // Button names
  96. char  _cwdImage[80];                   // Image working directory
  97.  
  98. IMAGE  *_undo=NULL;                    // Undo image buffer pointer.
  99.  
  100. PALETTEENTRY peGray  [64];             // Gray scale palette for gray images
  101. PALETTEENTRY pePseudo[64];             // Pseudo color palette for alternate
  102. PALETTEENTRY peUser [128];             // User programmable section
  103. PALETTEENTRY peMain [256];             // Primary system palette
  104.  
  105. HPALETTE hPalMain;                      // Handle to the current palette.
  106.  
  107. extern WORD hist[256];
  108.  
  109. // Default user file profile
  110. char _ext[5] = ".usr";
  111. int _hsize  =   0;
  112. int _psize  =   8;
  113. int _pshift =   8;
  114. int _width  = 512;
  115. int _height = 480;
  116.  
  117. //---------------------------------------
  118. // Module prototypes.
  119. //---------------------------------------
  120. #if defined(MODULE0)
  121. int MODULE0(HWND hWnd);
  122. #endif
  123. #if defined(MODULE1)
  124. int MODULE1(HWND hWnd);
  125. #endif
  126. #if defined(MODULE2)
  127. int MODULE2(HWND hWnd);
  128. #endif
  129. #if defined(MODULE3)
  130. int MODULE3(HWND hWnd);
  131. #endif
  132. #if defined(MODULE4)
  133. int MODULE4(HWND hWnd);
  134. #endif
  135. #if defined(MODULE5)
  136. int MODULE5(HWND hWnd);
  137. #endif
  138. #if defined(MODULE6)
  139. int MODULE6(HWND hWnd);
  140. #endif
  141. #if defined(MODULE7)
  142. int MODULE7(HWND hWnd);
  143. #endif
  144.  
  145. //--------------------------------------
  146. // External dialog windows.
  147. //--------------------------------------
  148. #if defined (DIALOG0)
  149. extern HWND DIALOG0;
  150. #endif
  151. #if defined (DIALOG1)
  152. extern HWND DIALOG1;
  153. #endif
  154. #if defined (DIALOG2)
  155. extern HWND DIALOG2;
  156. #endif
  157. #if defined (DIALOG3)
  158. extern HWND DIALOG3;
  159. #endif
  160. #if defined (DIALOG4)
  161. extern HWND DIALOG4;
  162. #endif
  163. #if defined (DIALOG5)
  164. extern HWND DIALOG5;
  165. #endif
  166. #if defined (DIALOG6)
  167. extern HWND DIALOG6;
  168. #endif
  169. #if defined (DIALOG7)
  170. extern HWND DIALOG7;
  171. #endif
  172.  
  173.  
  174.  
  175.  
  176.  
  177. /*
  178. ==========================================================================
  179. int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,
  180.                    LPSTR  lpCmdLine,int    nCmdShow)
  181.  
  182. Description:
  183.  
  184. WINDOWS ENTRY POINT CODE.
  185.  
  186. Windows initial entry point for the program. This is the startup code for
  187. the program. It initializes the top level window, sets up code sharing
  188. (if another instance of the program is running), and begins a message loop.
  189. This code should not be modified by module programmers.
  190.  
  191. If this function must abort before entering the msg loop, it returns the
  192. conventional value NULL.
  193. ==========================================================================
  194. */
  195. int PASCAL WinMain(HANDLE hInstance,        /* current instance       */
  196.                          HANDLE hPrevInstance,    /* previous instance      */
  197.                          LPSTR  lpCmdLine,        /* cmd line               */
  198.                          int    nCmdShow)         /* show type (open/icon)  */
  199.    {
  200.    int  x0,y0,w,h,cx,cy;
  201.    MSG  msg;
  202.    HWND hWnd;                              
  203.    WNDCLASS wc;
  204.  
  205.    hInst = hInstance;                            // Save the instance handle.
  206.    if (!hPrevInstance)                           // Other instances running?
  207.       {
  208.       wc.lpszClassName = MODULE"Main";           // Name for CreateWindow.
  209.       wc.style         = CS_DBLCLKS;             // Qualifying double clicks 
  210.       wc.lpfnWndProc   = (WNDPROC)WP_Main;       // Func to get msgs
  211.       wc.cbClsExtra    = 0;                      // No per-class extra data. 
  212.       wc.cbWndExtra    = 0;                      // No per-window extra data 
  213.       wc.hInstance     = hInstance;              // App that owns the class  
  214.       wc.hIcon         = LoadIcon(hInst,MODULE); // Loads icon 
  215.       wc.hCursor       = LoadCursor(NULL,IDC_ARROW);
  216.       wc.hbrBackground = COLOR_APPWORKSPACE+1;
  217.       wc.lpszMenuName  = MODULE;                 // Name of menu resource
  218.  
  219.       if (!RegisterClass(&wc))                   // Initialize new window class.
  220.          {
  221.          char sz[80];
  222.  
  223.          sprintf("Unable to register <%s> class",(char *)wc.lpszClassName);
  224.          MessageBeep(MB_ICONEXCLAMATION);
  225.          MessageBox(NULL,sz,"Error",MB_OK | MB_ICONEXCLAMATION);
  226.          return (FALSE);                         // Exits if unable.
  227.          }
  228.       }
  229.  
  230.    /*
  231.    Perform initializations that apply to a specific instance, those that 
  232.    cannot be shared by multiple instances. Save the instance handle in
  233.    static variable, which will be used in many subsequence calls from
  234.    this application to Windows.
  235.  
  236.    WRIPS is currently compatible with 3 display resolutions:
  237.  
  238.    1. 640x480  VGA             (VGA)
  239.    2. 800x600  Super VGA      (SVGA)
  240.    3. 1024x768 IBM 8514A/XGA   (XGA)
  241.    4. 1280x1024 std CAD/CAM    (CAD)
  242.    */
  243.  
  244.    x0=y0=0;
  245.    w=h=CW_USEDEFAULT;
  246.    cx = GetSystemMetrics(SM_CXSCREEN);      // Get the screen width in pixels
  247.    cy = GetSystemMetrics(SM_CYSCREEN);      // Get the screen height in pixels
  248.  
  249.    switch (cx)
  250.       {
  251.       case  VGA: x0=  0; y0=  0; w= cx-  0; h=cy-  0; break;
  252.       case SVGA: x0=  0; y0=  0; w= cx-  0; h=cy- 60; break;
  253.       case  XGA: x0=  0; y0=  0; w= cx-  0; h=cy- 80; break;
  254.       case  CAD: x0=100; y0=100; w= cx-200; h=cy-200; break;
  255.       }
  256.  
  257.  
  258.    hWnd = CreateWindow(
  259.       PGMNAME"Main",                        // See RegisterClass() call.
  260.       "Image Workframe",                    // Text for window title bar.
  261.       WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,// Use standard window style
  262.       x0,y0,w,h,                            // Set window startup coords 
  263.       NULL,                                 // No parent for overlapping
  264.       NULL,                                 // Use the window class menu. 
  265.       hInstance,                            // This instance owns this wnd 
  266.       NULL);                                // Pointer not needed.
  267.  
  268.    if (!hWnd)                               // If no window created
  269.       {
  270.       char sz[80];
  271.  
  272.       sprintf("Unable to create <%s> desktop window",PGMNAME);
  273.       MessageBeep(MB_ICONEXCLAMATION);
  274.       MessageBox(NULL,sz,"Error",MB_OK | MB_ICONEXCLAMATION);
  275.       return (FALSE);                       // Exits if unable.
  276.       }
  277.  
  278.    ShowWindow(hWnd,nCmdShow);               // Show the window 
  279.    UpdateWindow(hWnd);                      // Sends WM_PAINT msg 
  280.    lpCmdLine=lpCmdLine;                     // Suppress warning.
  281.  
  282.    // Acquire and dispatch messages until a WM_QUIT msg is received.
  283.    // This function exits the application instance by returning the 
  284.    // value passed by PostQuitMessage().
  285.  
  286.    while (GetMessage(&msg,NULL,NULL,NULL))
  287.       {
  288.         if (!ToolDlgMessage(&msg) && !UserDlgMessage(&msg))
  289.          {                                  // Dispatch to a window
  290.          TranslateMessage(&msg);            // Xlates virtual key codes
  291.          DispatchMessage(&msg);             // Dispatches msg to window
  292.          }
  293.       }
  294.    return(msg.wParam);                      // Returns PostQuitMessage
  295.    }
  296.  
  297.  
  298. /*
  299. ---------------------------------------------------------------------
  300. int ToolDlgMessage(MSG *msg)
  301. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  302. Dispatches messages designated for one of the tools includes in IWF.
  303. ---------------------------------------------------------------------
  304. */
  305. int ToolDlgMessage(MSG *msg)
  306.    {
  307.    int processed=0;
  308.    extern HWND hDlgPalMgr;
  309.    extern HWND hDlgProfiler;
  310.    extern HWND hDlgConvolver;
  311.    //extern HWND hDlgMatrox;
  312.  
  313.    if (!processed && IsWindow(hDlgPalMgr   ) && IsDialogMessage(hDlgPalMgr   ,msg)) processed=1;
  314.    if (!processed && IsWindow(hDlgProfiler ) && IsDialogMessage(hDlgProfiler ,msg)) processed=1;
  315.    if (!processed && IsWindow(hDlgConvolver) && IsDialogMessage(hDlgConvolver,msg)) processed=1;
  316.    //if (!processed && IsWindow(hDlgMatrox   ) && IsDialogMessage(hDlgMatrox   ,msg)) processed=1;
  317.  
  318.    return(processed);
  319.    }
  320.  
  321. /*
  322. ---------------------------------------------------------------------
  323. int UserDlgMessage(MSG *msg)
  324. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  325. Dispatches messages designated for one of the user modules.
  326. ---------------------------------------------------------------------
  327. */
  328. int UserDlgMessage(MSG *msg)
  329.    {
  330.    int processed=0;
  331.  
  332.    #if defined (DIALOG0)
  333.    if (!processed && IsWindow(DIALOG0) && IsDialogMessage(DIALOG0,msg)) processed=1;
  334.    #endif
  335.    #if defined (DIALOG1)
  336.    if (!processed && IsWindow(DIALOG1) && IsDialogMessage(DIALOG1,msg)) processed=1;
  337.    #endif
  338.    #if defined (DIALOG2)
  339.    if (!processed && IsWindow(DIALOG2) && IsDialogMessage(DIALOG2,msg)) processed=1;
  340.    #endif
  341.    #if defined (DIALOG3)
  342.    if (!processed && IsWindow(DIALOG3) && IsDialogMessage(DIALOG3,msg)) processed=1;
  343.    #endif
  344.    #if defined (DIALOG4)
  345.    if (!processed && IsWindow(DIALOG4) && IsDialogMessage(DIALOG4,msg)) processed=1;
  346.    #endif
  347.    #if defined (DIALOG5)
  348.    if (!processed && IsWindow(DIALOG5) && IsDialogMessage(DIALOG5,msg)) processed=1;
  349.    #endif
  350.    #if defined (DIALOG6)
  351.    if (!processed && IsWindow(DIALOG6) && IsDialogMessage(DIALOG6,msg)) processed=1;
  352.    #endif
  353.    #if defined (DIALOG7)
  354.    if (!processed && IsWindow(DIALOG7) && IsDialogMessage(DIALOG7,msg)) processed=1;
  355.    #endif
  356.  
  357.    msg = msg;
  358.    return(processed);
  359.    }
  360.  
  361.  
  362. /*
  363. ==========================================================================
  364. long far PASCAL _export WP_Main(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam)
  365.  
  366. Description:
  367.  
  368. MAIN MESSAGE DISPATCHER CODE.
  369.  
  370. This is the windows main messaging loop which is specifically constructed to
  371. provide a message dispatcher for multiple modules of code attached to WRIPS.
  372.  
  373. This procedure handles all the primary message handling from the window.
  374. This includes not only the main menu selections but specific messages
  375. generates by the Windows environment. This code should only be modified to
  376. allow the module programmers to had menu access for their code.
  377. ==========================================================================
  378. */
  379. long far PASCAL _export WP_Main(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam)
  380.    {
  381.    switch (wMsg)
  382.       {
  383.       case WM_CREATE:
  384.       // Create the push buttons for launching user modules.
  385.       {
  386.       int  i;
  387.       DWORD dwStyle;
  388.  
  389.       dwStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON;
  390.  
  391.       for (i=0; i<8; ++i)
  392.          strcpy(_name[i],"");
  393.  
  394.       #if defined(NAME0)
  395.       strcpy(_name[0],NAME0);
  396.       #endif
  397.       #if defined(NAME1)
  398.       strcpy(_name[1],NAME1);
  399.       #endif
  400.       #if defined(NAME2)
  401.       strcpy(_name[2],NAME2);
  402.       #endif
  403.       #if defined(NAME3)
  404.       strcpy(_name[3],NAME3);
  405.       #endif
  406.       #if defined(NAME4)
  407.       strcpy(_name[4],NAME4);
  408.       #endif
  409.       #if defined(NAME5)
  410.       strcpy(_name[5],NAME5);
  411.       #endif
  412.       #if defined(NAME6)
  413.       strcpy(_name[6],NAME6);
  414.       #endif
  415.       #if defined(NAME7)
  416.       strcpy(_name[7],NAME7);
  417.       #endif
  418.  
  419.       for (i=0; i<7 && _name[i][0]; ++i)
  420.          _hWndTool[i] = CreateWindow("button",_name[i],dwStyle,i*74,0,75,25,hWnd,1000+i,hInst,NULL);
  421.       }
  422.  
  423.       _undo = NULL;                              // Set undo buffer to empty.
  424.       Status(hWnd);                              // Launch the status window.
  425.  
  426.       hPalMain = CreateLogPalette(256);          // Create a logical system palette
  427.       FillColors();                              // Fill the color tables
  428.  
  429.       PostMessage(hWnd,WM_USER  ,0,0);           // Post Message to Menu
  430.       PostMessage(hWnd,WM_COMMAND,999,0);       // Post Message to About Box
  431.       break;
  432.  
  433.       // THE IMAGE DESKTOP NEEDS REPAINTING
  434.       case WM_PAINT:
  435.       {
  436.       PAINTSTRUCT ps;
  437.  
  438.       BeginPaint(hWnd,&ps);                      // Set up a DC for paint
  439.       EndPaint(hWnd,&ps);                        // Return the display DC
  440.       }
  441.       break;
  442.  
  443.       // THE IMAGE DESKTOP HAS BEEN SIZED OR MOVED.
  444.       case WM_SIZE:
  445.       case WM_MOVE:
  446.       PostMessage(hWndStatus,wMsg,hWnd,lParam);  // Post msg to status window.
  447.       break;
  448.  
  449.       // SYSTEM PALETTED CHANGED.
  450.       case WM_PALETTECHANGED:
  451.       {
  452.       int n;
  453.  
  454.       PostMessage(hWndStatus,wMsg,hWnd,lParam);  // Post msg to status window.
  455.  
  456.       // Re-paint the image windows which do not have input focus.
  457.       for (n=0; n<MAXIMAGES; ++n)
  458.          if (IsWindow(_hWndImage[n]) && (_hWndImage[n]!=(HWND)wParam))
  459.              InvalidateRect(_hWndImage[n],NULL,FALSE);
  460.       }
  461.       break;
  462.  
  463.       // IMAGE ACTIVE/INACTIVE
  464.       case WM_USER:
  465.       {
  466.       int i;
  467.       HMENU hMenu;
  468.  
  469.       Load_Settings();
  470.       hMenu = GetMenu(hWnd);
  471.       if (IsWindow(wParam))                      // Active image handle.
  472.          {
  473.          EnableMenuItem(GetSubMenu(hMenu,0),2,MF_ENABLED | MF_BYPOSITION);
  474.          EnableMenuItem(GetSubMenu(hMenu,0),3,MF_ENABLED | MF_BYPOSITION);
  475.          for (i=1; i<=4; ++i)
  476.             EnableMenuItem(hMenu,i,MF_ENABLED | MF_BYPOSITION);
  477.          }
  478.       else                                       // No active image.
  479.          {
  480.          EnableMenuItem(GetSubMenu(hMenu,0),2,MF_GRAYED | MF_BYPOSITION);
  481.          EnableMenuItem(GetSubMenu(hMenu,0),3,MF_GRAYED | MF_BYPOSITION);
  482.          for (i=1; i<=4; ++i)
  483.             EnableMenuItem(hMenu,i,MF_GRAYED | MF_BYPOSITION);
  484.          }
  485.       DrawMenuBar(hWnd);
  486.       }
  487.       break;
  488.  
  489.       // A MAIN MENU COMMAND HAS BEEN ISSUED
  490.       case WM_COMMAND:
  491.       if (wParam>100 && wParam<200)
  492.          {
  493.          switch (wParam)
  494.              {
  495.             //------------------------- FILE MENU -----------------------------
  496.             // NEW FILE
  497.              case 101:
  498.             FileNew (hWnd);
  499.             break;
  500.  
  501.             // OPEN AN EXISTING FILE
  502.              case 102:
  503.             FileOpen(hWnd);
  504.             break;
  505.  
  506.             // SAVE THE SOURCE IMAGE
  507.              case 103:
  508.             FileSave(hWnd);
  509.             break;
  510.  
  511.             // SAVE THE SOURCE IMAGE AS A NEW NAME
  512.              case 104:
  513.             FileSaveAs(hWnd);
  514.             break;
  515.  
  516.             // CLOSE IWF
  517.              case 108:
  518.             PostMessage(hWnd,WM_CLOSE,0,0);
  519.             break;
  520.  
  521.             // SET USER FILE OPTIONS
  522.             case 109:
  523.             CallDialogBox(hWnd,DP_UserFile,"USER_FILE");
  524.             break;
  525.             }
  526.          }
  527.  
  528.       if (wParam>200 && wParam<900 && IsWindow(hWndSrc))
  529.          {
  530.          IMAGE *image;
  531.  
  532.           if (IsWindow(hWndSrc))
  533.               image = GetImage(hWndSrc);           // Get attached data set.
  534.          else
  535.             {
  536.             MessageBox(NULL,"No source image!","WP_Main",MB_OK);
  537.             break;
  538.             }
  539.  
  540.          SetCursor(LoadCursor(NULL,IDC_WAIT));   // Set Hourglass cursor.
  541.          switch (wParam)
  542.              {
  543.             //------------------------- EDIT MENU -----------------------------
  544.             // UNDO/REDO THE LAST CHANGES TO THE IMAGE
  545.             case 210:
  546.             if (!GetUndoImage())
  547.                {
  548.                MessageBox(NULL,"Nothing to undo","Image Workframe",MB_OK);
  549.                break;
  550.                }
  551.             SetImage(hWndSrc,_undo);                   // Attach undo image
  552.             if (_undo->hres!=image->hres || _undo->vres!=image->vres)
  553.                PostMessage(hWndSrc,WM_USER,0,0);          // Re-do window
  554.             _undo = image;                             // Set undo image to previous
  555.             break;
  556.  
  557.             case 220:                            break;
  558.             case 230:                            break;
  559.             case 240:                            break;
  560.  
  561.             // MAKE A DUPLICATE OF THE SOURCE IMAGE
  562.             case 250:
  563.             DuplicateImageWindow(hWndSrc);
  564.             break;
  565.  
  566.             // SELECT THE ENTIRE IMAGE AREA
  567.             case 260:
  568.              SetRect(&image->rc,0,0,image->hres,image->vres);
  569.             break;
  570.  
  571.             //------------------------- VIEW MENU -----------------------------
  572.             // SET THE IMAGE DISPLAY TO 100%
  573.             case 310:
  574.             if (GetScale(hWndSrc)!=100)
  575.                {
  576.                SetScale(hWndSrc,100);
  577.                 PostMessage(hWndSrc,WM_USER,0,0);    // Force image window rebuild
  578.                }
  579.             break;
  580.  
  581.             // ZOOM IN THE IMAGE
  582.             case 320:
  583.             {
  584.             int scale;
  585.  
  586.             scale = GetScale(hWndSrc);
  587.             if (scale<400)
  588.                {
  589.                SetScale(hWndSrc,scale*2);
  590.                 PostMessage(hWndSrc,WM_USER,0,0);    // Force image window rebuild
  591.                }
  592.             }
  593.             break;
  594.  
  595.             // ZOOM OUT THE IMAGE
  596.             case 330:
  597.             {
  598.             int scale;
  599.  
  600.             scale = GetScale(hWndSrc);
  601.             if (scale>25)
  602.                {
  603.                SetScale(hWndSrc,scale/2);
  604.                 PostMessage(hWndSrc,WM_USER,0,0);    // Force image window rebuild
  605.                }
  606.             }
  607.             break;
  608.  
  609.             // DISPLAY THE IMAGE INFO
  610.             case 340:
  611.             CallDialogBox(hWnd,DP_Info,"INFO");
  612.             break;
  613.  
  614.             //------------------------- IMAGE TOOLS ------------------------
  615.             // PERFORM IMAGE SCALING
  616.             case 410:
  617.             CallDialogBox(hWnd,DP_Scale,"SCALE");
  618.             break;
  619.  
  620.             // PERFORM IMAGE TRANSFORMATION
  621.             case 420:
  622.             CallDialogBox(hWnd,DP_Transform,"TRANSFORM");
  623.             break;
  624.  
  625.             // PERFORM FRAME TO FRAME OPERATIONS
  626.             case 430:
  627.             CallDialogBox(hWnd,DP_Frame,"FRAME");
  628.             break;
  629.  
  630.             // MATROX MVP-AT FRAME GRABBER TOOL
  631.             case 450:
  632.             //Matrox(hWnd);
  633.             break;
  634.  
  635.             //------------------------- REGION TOOLS ----------------------
  636.             // START HISTOGRAM TOOL
  637.             case 610:
  638.             Histogram(hWnd);
  639.             break;
  640.  
  641.             // START PROFILER TOOL
  642.             case 620:
  643.             Profiler(hWnd);
  644.             break;
  645.  
  646.             // START IMAGE CONVOLUTION TOOL
  647.             case 630:
  648.             Convolver(hWnd);
  649.             break;
  650.  
  651.             // START RENDER TOOL
  652.             case 640:
  653.             Render(hWnd);
  654.             break;
  655.             }
  656.  
  657.          SetCursor(LoadCursor(NULL,IDC_ARROW));     // Restore arrow cursor.
  658.          InvalidateRect(hWndSrc,NULL,FALSE);        // Invalidate image
  659.          }
  660.  
  661.       if (wParam>900 && wParam<1000)
  662.          switch (wParam)
  663.             {
  664.             // DISPLAY NOT AVAILABLE BOX
  665.                 case 998:
  666.             MessageBox(hWnd,"Item not yet available","IWF",MB_OK);
  667.             break;
  668.  
  669.             // DISPLAY ABOUT BOX
  670.                 case 999:
  671.             CallDialogBox(hWnd,DP_About,"ABOUT");
  672.             break;
  673.             }
  674.  
  675.       // USER MODULESS
  676.       if (wParam >= 1000)
  677.          switch (wParam)
  678.             {
  679.             // Creation procedures for user modules
  680.             #if defined(MODULE0)
  681.             case 1000: MODULE0(hWnd); break;
  682.             #endif
  683.             #if defined(MODULE1)
  684.             case 1001: MODULE1(hWnd); break;
  685.             #endif
  686.             #if defined(MODULE2)
  687.             case 1002: MODULE2(hWnd); break;
  688.             #endif
  689.             #if defined(MODULE3)
  690.             case 1003: MODULE3(hWnd); break;
  691.             #endif
  692.             #if defined(MODULE4)
  693.             case 1004: MODULE4(hWnd); break;
  694.             #endif
  695.             #if defined(MODULE5)
  696.             case 1005: MODULE5(hWnd); break;
  697.             #endif
  698.             #if defined(MODULE6)
  699.             case 1006: MODULE6(hWnd); break;
  700.             #endif
  701.             #if defined(MODULE7)
  702.             case 1007: MODULE7(hWnd); break;
  703.             #endif
  704.             }
  705.       break;
  706.  
  707.       case WM_CLOSE:                             // REQUEST TO EXIT PGM.
  708.       {
  709.       char sz[80];
  710.     
  711.       sprintf(sz,"Exit Image Workframe?");
  712.       if (MessageBox(hWnd,sz,"EXIT",MB_YESNO | MB_ICONQUESTION) == IDYES)
  713.          {
  714.          DestroyWindow(hWnd);
  715.          }
  716.       }
  717.       break;
  718.  
  719.       case WM_DESTROY:                           // WINDOW IS TO BE DESTROYED.
  720.       if (_undo)
  721.             _undo = DestroyImage(_undo);
  722.       DeleteObject(hPalMain);                    // Delete palette.
  723.       PostQuitMessage(0);                        // Tell program to quit.
  724.       break;
  725.  
  726.       default:                                   // Pass on if unprocessed.
  727.       return(DefWindowProc(hWnd, wMsg, wParam, lParam));
  728.       }
  729.  
  730.    return(NULL);
  731.    }
  732.  
  733. /*
  734. ------------------------------------------------------------------------
  735. Load_Settings(void)
  736.  
  737. Description:
  738. Loads the module settings from disk file.
  739. ------------------------------------------------------------------------
  740. */
  741. static void Load_Settings(void)
  742.    {
  743.    FILE *fp;
  744.  
  745.    fp = fopen("iwf.ini","r");
  746.    if (!fp)
  747.       {
  748.       MessageBeep(-1);
  749.       MessageBox(NULL,"Cannot open initialization file",MODULE,MB_OK);
  750.       return;
  751.       }
  752.  
  753.    Load_Item(fp,"header"    ,&_hsize,1);
  754.    Load_Item(fp,"pixelsize" ,&_psize, 1);
  755.    Load_Item(fp,"pixelshift",&_pshift,1);
  756.    Load_Item(fp,"imagewidth",&_width ,1);
  757.    Load_Item(fp,"imageheight",&_height,1);
  758.  
  759.    fclose(fp);
  760.    }
  761.  
  762.  
  763.  
  764. /*
  765. ---------------------------------------------------------------------
  766. HPALETTE CreateLogPalette(int size)
  767.  
  768. Creates a logical palette for mapping into the system palette.
  769. ---------------------------------------------------------------------
  770. */
  771. HPALETTE CreateLogPalette(int size)
  772.    {
  773.    LOGPALETTE *npPal;
  774.    HPALETTE hPal;
  775.  
  776.    npPal = (LOGPALETTE *)LocalAlloc(LPTR,sizeof(LOGPALETTE)+size*sizeof(PALETTEENTRY));
  777.    npPal->palVersion    = 0x300;              // Windows version
  778.    npPal->palNumEntries = size;               // Palette size
  779.  
  780.    hPal = CreatePalette((LPLOGPALETTE)npPal); // Create a logical palette
  781.  
  782.    LocalFree((LOCALHANDLE)npPal);             // Free the palette info structure
  783.  
  784.    return(hPal);             
  785.    }
  786.  
  787.  
  788. /*
  789. ---------------------------------------------------------------------
  790.  
  791. ---------------------------------------------------------------------
  792. */
  793. void FillColors(void)
  794.       {
  795.       int i,intensity;
  796.  
  797.       // Create a 64 level grey section for normal image display.
  798.       for (i=0; i<64; i++)
  799.          {
  800.          peGray[i].peRed   = i*4;
  801.          peGray[i].peGreen = i*4;
  802.          peGray[i].peBlue  = i*4;
  803.          peGray[i].peFlags = NULL;
  804.          }
  805.  
  806.       for (i=0; i<125; i++)
  807.          {
  808.          peUser[i].peRed   = (i/ 1)%5 * 63;
  809.          peUser[i].peGreen = (i/ 5)%5 * 63;
  810.          peUser[i].peBlue  = (i/25)%5 * 63;
  811.          peUser[i].peFlags = NULL;
  812.          }
  813.  
  814.       for (i=0; i<64; ++i)
  815.          {
  816.          pePseudo[i].peRed   = 0;
  817.          pePseudo[i].peGreen = 0;
  818.          pePseudo[i].peBlue  = 0;
  819.          pePseudo[i].peFlags = NULL;
  820.          }
  821.  
  822.       for (i=0; i<8; ++i)
  823.          {
  824.          intensity = (i*16+i);
  825.  
  826.          pePseudo[i+ 0].peRed   = 0;
  827.          pePseudo[i+ 8].peRed   = 0;
  828.          pePseudo[i+16].peRed   = 0;
  829.          pePseudo[i+24].peRed   = 0;
  830.          pePseudo[i+32].peRed   = 0   + intensity;
  831.          pePseudo[i+40].peRed   = 128 + intensity;
  832.          pePseudo[i+48].peRed   = 255;
  833.          pePseudo[i+56].peRed   = 255;
  834.  
  835.          pePseudo[i+ 0].peBlue  = 128 + intensity;
  836.          pePseudo[i+ 8].peBlue  = 255;
  837.          pePseudo[i+16].peBlue  = 255 - intensity;
  838.          pePseudo[i+24].peBlue  = 127 - intensity;
  839.          pePseudo[i+32].peBlue  = 0;
  840.          pePseudo[i+40].peBlue  = 0;
  841.          pePseudo[i+48].peBlue  = 0;
  842.          pePseudo[i+56].peBlue  = 0;
  843.  
  844.          pePseudo[i+ 0].peGreen = 0;
  845.          pePseudo[i+ 8].peGreen =   0 + intensity;
  846.          pePseudo[i+16].peGreen = 128 + intensity;
  847.          pePseudo[i+24].peGreen = 255 - intensity;
  848.          pePseudo[i+32].peGreen = 128;
  849.          pePseudo[i+40].peGreen = 128 + intensity;
  850.          pePseudo[i+48].peGreen = 255 - intensity;
  851.          pePseudo[i+56].peGreen = 127 - intensity;
  852.          }
  853.  
  854.       for (i=0; i<64; ++i)
  855.          {
  856.          peMain[i+  0] = peGray[i];
  857.          peMain[i+ 64] = pePseudo[i];
  858.          peMain[i+128] = peUser[i];
  859.          peMain[i+192] = peUser[i+64];
  860.          }
  861.       }
  862.  
  863. /*
  864. --------------------------------------------------------------------------
  865.  
  866. --------------------------------------------------------------------------
  867. */
  868. void SetUndoImage(IMAGE *image)
  869.     {
  870.     if (_undo)                                    // Check for undo image
  871.         _undo = DestroyImage(_undo);                 // Destroy the undo image
  872.     if (_undo)                                    // Check for undo image
  873.         {                                          // Error if it exists
  874.         MessageBox(NULL,"Unable to free undo buffer","Image Workframe",MB_OK);
  875.         return;
  876.         }
  877.     _undo = image;
  878.     }
  879.  
  880. /*
  881. --------------------------------------------------------------------------
  882.  
  883. --------------------------------------------------------------------------
  884. */
  885. IMAGE *GetUndoImage(void)
  886.     {
  887.     return(_undo);
  888.     }
  889.  
  890. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ End of IWF.C ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  891.